#include "walle.h"
#include <iostream>
Walle::Walle()
{
	HWND gameWnd = NULL;
	while(gameWnd = ::FindWindowEx(NULL, gameWnd, L"GxWindowClassD3d", NULL)){
		gameWnds_.push_back(gameWnd);
	}
	if(gameWnds_.size() == 0){
		throw NoGame();
	}
}
void Walle::run()
{
	char keys[] = {'1', '2', '3'};
	for(;;){
		for(int i = 0; i < 3; ++i){
			std::cout << "Press " << keys[i] << " for ";
			std::vector<HWND>::iterator beg = gameWnds_.begin();
			std::vector<HWND>::iterator end = gameWnds_.end();
			for(; beg != end; ++beg){
				std::cout << *beg << std::endl;
				::SwitchToThisWindow(*beg, FALSE);
				keybd_event(LOBYTE(VkKeyScan(keys[i])), 0, 0 , 0); //  Press
				keybd_event(LOBYTE(VkKeyScan(keys[i])), 0, KEYEVENTF_KEYUP,0); // Release
				::Sleep(400);
			}
		}
	}
}